// pages/list/index.js
import wxRequest from '../../utils/wxRequest.js'
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    // tab切换    
    currentTab: 0,
    limit: 6, //等级
    data1: [],
    data2: [],
    data3: []
  },
  swichNav: function(e) {
    var that = this;
    wx.showToast({
      icon: 'loading',
    })
    if (e) {
      that.setData({
        limit: e.currentTarget.dataset.limit
      });
      if (that.data.currentTab === e.currentTarget.dataset.current) {
        return false;
      } else {
        that.setData({
          currentTab: e.target.dataset.current,
        })
      }
    }
    that.getData();
  },
  getData() {
    var that = this;
    wxRequest.getRequest('/zp/zp/ranking', {
      limit: that.data.limit
    }).then(res => {
      switch (that.data.limit) {
        case 6:
          that.setData({
            data1: res.data
          });
          break;
        case 8:
          that.setData({
            data2: res.data
          });
          break;
        case 10:
          that.setData({
            data3: res.data
          });
          break;
        default:
          that.setData({
            data1: res.data
          });
          break;
      }
      wx.hideToast();
    })
  },
  swiperChange: function(e) {
    wx.showToast({
      icon: 'loading',
    })
    var that = this;
    that.setData({
      currentTab: e.detail.current,
    })
    switch (e.detail.current) {
      case 0:
        that.setData({
          limit: 6
        })
        break;
      case 1:
        that.setData({
          limit: 8
        })
        break;
      case 2:
        that.setData({
          limit: 10
        })
        break;
    }
    that.getData();

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.swichNav();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {
    return {
      title: ' 挑战2019排行榜',
      path: '/pages/rank/index'
    }
  }
})